package com.hangxiang.approval.controller;

import com.github.pagehelper.PageInfo;
import com.hangxiang.approval.common.*;
import com.hangxiang.approval.service.ApplyService;
import com.hangxiang.approval.vo.ApplyInfoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 申请表(Apply)表控制层
 *
 * @author makejava
 * @since 2020-11-23 18:05:08
 */
@RestController
@RequestMapping("apply")
@Api(tags = "申请表Apply相关功能")
public class ApplyController {
    /**
     * 服务对象
     */
    @Resource
    private ApplyService applyService;

    /**
     * 通过主键查询单条数据
     *
     * @param common 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    @ApiOperation(value = "通过主键查询单条数据")
    @ResponseBody
    public ResultBean selectOne(@RequestBody @Validated IntegerCommon common) {
        return ResultBean.success(applyService.queryById(common));
    }

    /**
     * 新增数据
     *
     * @param applyInsertCommon 实例对象
     * @return 实例对象
     */
    @PostMapping("insertApply")
    @ApiOperation(value = "发起申请")
    @ResponseBody
    public ResultBean insert(@RequestBody @Validated ApplyInsertCommon applyInsertCommon) {
        return ResultBean.success(applyService.insertApply(applyInsertCommon));
    }

    /**
     * 新增数据
     *
     * @param applyUpdateCommon 实例对象
     * @return 实例对象
     */
    @PostMapping("updateApply")
    @ApiOperation(value = "修改数据")
    @ResponseBody
    public ResultBean update(@RequestBody @Validated ApplyUpdateCommon applyUpdateCommon) {
        return ResultBean.success(applyService.updateApply(applyUpdateCommon));
    }

    @PostMapping("findAll")
    @ApiOperation(value = "条件分页查询列表")
    @ResponseBody
    public ResultBean findAll(@RequestBody @Validated PageApplyCommon common){
        return ResultBean.success(applyService.findAll(common));
    }

    @PostMapping("findApplyInfo")
    @ApiOperation(value = "根据id查询申请明细")
    @ResponseBody
    public ResultBean findApplyInfo(@RequestBody @Validated IntegerCommon common){
        return ResultBean.success(applyService.findApplyInfo(common));
    }

    @PostMapping("examineApply")
    @ApiOperation(value = "审批")
    @ResponseBody
    public ResultBean examineApply(@RequestBody @Validated ExamineApplyCommon common){
        applyService.examineApply(common);

        return ResultBean.success();
    }



    @PostMapping("examineList")
    @ApiOperation(value = "查询审批列表")
    @ResponseBody
    public ResultBean examineList(@RequestBody @Validated ExamineListPageCommon common){
        ResultBean resultBean = new ResultBean();
        return resultBean.success(applyService.examineList(common));
    }


    @PostMapping("duplicateList")
    @ApiOperation(value = "查询抄送列表")
    @ResponseBody
   public ResultBean duplicateList(@RequestBody @Validated ExamineListPageCommon common){
        ResultBean resultBean = new ResultBean();
       return resultBean.success(applyService.duplicateList(common));
   }

}